//
//  BZMeService.m
//  BZMeComponent
//
//  Created by 郭艺伟 on 2017/10/11.
//  Copyright © 2017年 郭艺伟. All rights reserved.
//

#import "BZMeService.h"

@interface BZMeService()

@property (nonatomic, strong) BZBaseRequestModel *requestModel;

@property (nonatomic, strong) BZBaseRequest      *baseRequest;

@end

@implementation BZMeService

- (BZBaseRequestModel *)requestModel{
    
    if (!_requestModel) {
        _requestModel = [[BZBaseRequestModel alloc]init];
        _requestModel.hasSessionId = YES;
    }
    return _requestModel;
}

- (BZBaseRequest *)baseRequest{
    
    if (!_baseRequest) {
        _baseRequest = [[BZBaseRequest alloc]init];
    }
    return _baseRequest;
}

- (void)fetchRequestWithParam:(NSDictionary *)param
                   requestUri:(NSString *)requestUri
                   httpMethod:(BZRequestType)requestType
                 hasSessionId:(BOOL)hasSessionId
                      success:(void(^)(NSString *code , id responseObject))success
                      failure:(void(^)(NSString *code,NSError *error))failure{
    
    self.requestModel.param = param;
    self.requestModel.requestUri = requestUri;
    self.requestModel.requestType = requestType;
    
    [self.baseRequest requestByModelAsync:self.requestModel success:success failure:failure];
    
}


- (void)getCurrentUserInfoSuccess:(void (^)(NSString * code, id responseObject))success
                                failure:(void (^)(NSString * code, NSError *error))failure{
    
    [self fetchRequestWithParam:nil requestUri:@"api/purview/user/info" httpMethod:BZPostRequest hasSessionId:YES success:success failure:failure];
    
}

- (void)modifyUserProfileByRequestParam:(NSDictionary *)requestParam
                               success:(void (^)(NSString * code, id responseObject))success
                               failure:(void (^)(NSString * code, NSError *error))failure{
    
    [self fetchRequestWithParam:requestParam requestUri:@"api/purview/user/edit-base" httpMethod:BZPostRequest hasSessionId:YES success:success failure:failure];
    
}
- (void)getUploadTokenSuccess:(void (^)(NSString * code, id responseObject))success
                            failure:(void (^)(NSString * code, NSError *error))failure{
    
    [self fetchRequestWithParam:nil requestUri:@"api/base/qiniu/uptoken" httpMethod:BZGetRequest hasSessionId:YES success:success failure:failure];
    
}

- (void)modifyUserInfoAllByRequestParam:(NSDictionary *)requestParam
                               success:(void (^)(NSString * code, id responseObject))success
                               failure:(void (^)(NSString * code, NSError *error))failure{
    
    [self fetchRequestWithParam:requestParam requestUri:@"api/purview/user/edit-info" httpMethod:BZPostRequest hasSessionId:YES success:success failure:failure];
    
}


- (void)getCoverUploadTokenByFileName:(NSString *)fileName
                              success:(void (^)(NSString * code, id responseObject))success
                              failure:(void (^)(NSString * code, NSError *error))failure{
    
    if (![fileName length]) {
        
        return;
    }
    
    NSDictionary *requestParam = @{@"key":fileName};
    
    [self fetchRequestWithParam:requestParam requestUri:@"api/base/qiniu/uptoken/replace" httpMethod:BZGetRequest hasSessionId:YES success:success failure:failure];
    
}


- (void)feedbackByRequestParam:(NSDictionary *)requestParam
                       success:(void (^)(NSString * code, id responseObject))success
                       failure:(void (^)(NSString * code, NSError *error))failure{
    
    [self fetchRequestWithParam:requestParam requestUri:@"api/app/feedback" httpMethod:BZPostRequest hasSessionId:YES success:success failure:failure];
    
}

- (void)modifyBindPhoneNumByRequestParam:(NSDictionary *)requestParam
                                 success:(void (^)(NSString * code, id responseObject))success
                                 failure:(void (^)(NSString * code, NSError *error))failure{
    
    [self fetchRequestWithParam:requestParam requestUri:@"api/purview/user/edit-phone" httpMethod:BZPostRequest hasSessionId:YES success:success failure:failure];
    
}

@end
